package utils;

import java.util.Hashtable;
import java.util.Map;

public class ObjectSample {

	private static Map<Class<? extends Object>, Object> map_sample = new Hashtable<Class<? extends Object>, Object>();
	
	@SuppressWarnings("unchecked")
	public static <T> T getSample(Class<T> clazz){
		Object obj = map_sample.get(clazz);
		T t = null;
		if(obj!=null){
			t = (T) obj;
		}else{
			try {
				t = clazz.newInstance();
				map_sample.put(clazz, t);
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		
		return t;
	}
	
}
